﻿@page "/gatewayruntime/hardwareinfo"
@namespace ThingsGateway.Gateway.Blazor
@using System.Linq.Expressions;
@using BlazorComponent;
@using Mapster;
@using Masa.Blazor.Presets;
@using System.IO;
@using Masa.Blazor;
@using Microsoft.AspNetCore.Authorization;

@using ThingsGateway.Admin.Blazor;
@using ThingsGateway.Admin.Core;
@using ThingsGateway.Core.Extension
@attribute [Authorize]
@attribute [RolePermission]
@inherits BaseComponentBase
@inject UserResoures UserResoures

<MRow NoGutters>
    <MCol Md=4 Cols="12">
        <MCard Style=@($"height:350px;overflow-y:auto") Elevation="1" Class="ma-2">
            <MCardSubtitle Class="text-subtitle-1">
                <span>@AppService.I18n.T("系统信息")</span>
            </MCardSubtitle>
            <MDivider></MDivider>

            <div class="ml-4 mr-4 d-flex flex-column ">

                <div class="mt-1  d-flex align-center justify-space-between">
                    <span class="text-subtitle-1 grey--text">@_hardwareInfoWorker.APPInfo.MachineInfo.Description(a => a.OSName)</span>
                    <span class="text-subtitle-2">@_hardwareInfoWorker.APPInfo.MachineInfo.OSName</span>
                </div>

                <div class="mt-1  d-flex align-center justify-space-between">
                    <span class="text-subtitle-1 grey--text">@_hardwareInfoWorker.APPInfo.MachineInfo.Description(a => a.OSVersion)</span>
                    <span class="text-subtitle-2">@_hardwareInfoWorker.APPInfo.MachineInfo.OSVersion</span>
                </div>
                <div class="mt-1  d-flex align-center justify-space-between">
                    <span class="text-subtitle-1 grey--text">@_hardwareInfoWorker.APPInfo.Description(a => a.UUID)</span>
                    <span class="text-subtitle-2" title=@_hardwareInfoWorker.APPInfo.UUID style="max-width:200px; white-space: nowrap !important;overflow: hidden !important; text-overflow: ellipsis !important;">@_hardwareInfoWorker.APPInfo.UUID</span>
                </div>

                <div class="mt-1  d-flex align-center justify-space-between">
                    <span class="text-subtitle-1 grey--text">@_hardwareInfoWorker.APPInfo.Description(a => a.OsArchitecture)</span>
                    <span class="text-subtitle-2">@_hardwareInfoWorker.APPInfo.OsArchitecture</span>
                </div>
                <div class="mt-1  d-flex align-center justify-space-between">
                    <span class="text-subtitle-1 grey--text">@_hardwareInfoWorker.APPInfo.Description(a => a.FrameworkDescription)</span>
                    <span class="text-subtitle-2">@_hardwareInfoWorker.APPInfo.FrameworkDescription</span>
                </div>
                <div class="mt-1  d-flex align-center justify-space-between">
                    <span class="text-subtitle-1 grey--text">@_hardwareInfoWorker.APPInfo.Description(a => a.Environment)</span>
                    <span class="text-subtitle-2">@_hardwareInfoWorker.APPInfo.Environment</span>
                </div>
                <div class="mt-1  d-flex align-center justify-space-between">
                    <span class="text-subtitle-1 grey--text">@_hardwareInfoWorker.APPInfo.Description(a => a.Stage)</span>
                    <span class="text-subtitle-2">@_hardwareInfoWorker.APPInfo.Stage</span>
                </div>
                <div class="mt-1  d-flex align-center justify-space-between">
                    <span class="text-subtitle-1 grey--text">@_hardwareInfoWorker.APPInfo.Description(a => a.UpdateTime)</span>
                    <span class="text-subtitle-2">@_hardwareInfoWorker.APPInfo.UpdateTime</span>
                </div>
            </div>
        </MCard>
    </MCol>

    <MCol Md=8 Cols="12">
        <MCard Style="height:350px;overflow-y:auto" Elevation="1" Class="ma-2">
            <MCardSubtitle Class="text-subtitle-1">
                <span>@AppService.I18n.T("硬件信息")</span>
            </MCardSubtitle>
            <MDivider></MDivider>
            <MRow NoGutters>
                <MCol Md=4 Cols="12" Class="pl-2 pr-2 d-flex justify-space-around">
                    <div class="pl-2 pr-2 d-flex flex-column  align-center">
                        @{
                            var item = _hardwareInfoWorker.APPInfo.MachineInfo.CpuRate;
                        }
                        <MProgressCircular Value=@(item*100<=100?item*100:100) Size="160" Width="12" Class="ma-4" Color=@(item*100>70?"red":"green")>
                            <div class="pl-2 pr-2 d-flex flex-column align-center">
                                @((item * 100).ToString("F0") + " %")
                            </div>
                        </MProgressCircular>

                        <div class="mt-1  d-flex align-center justify-space-between">
                            <span class="text-caption">@(_hardwareInfoWorker.APPInfo.MachineInfo.Processor)</span>
                        </div>
                    </div>

                </MCol>
                <MCol Md=4 Cols="12" Class="pl-2 pr-2 d-flex justify-space-around">
                    <div class="pl-2 pr-2 d-flex flex-column  align-center">
                        @{
                            var availableMemory = _hardwareInfoWorker.APPInfo.MachineInfo.AvailableMemory;
                            var memory = _hardwareInfoWorker.APPInfo.MachineInfo.Memory;
                        }
                        <MProgressCircular Value=@(memory>availableMemory?100 - (availableMemory * 100.00 / memory):100) Size="160" Width="12" Class="ma-4" Color=@(availableMemory * 100.00 / memory<20?"red":"green")>
                            <div class="pl-2 pr-2 d-flex flex-column  align-center">
                                @((100 - (availableMemory * 100.00 / memory)).ToString("F2") + " %")
                                <div class="pt-1  d-flex align-center justify-space-between">
                                    <span class="text-caption grey--text mx-2">可用</span>
                                    <span class="text-caption ">@((availableMemory / 1024.00 / 1024 / 1024).ToString("F2") + " GB")</span>
                                </div>
                                <div class="pt-1  d-flex align-center justify-space-between">
                                    <span class="text-caption grey--text mx-2">总</span>
                                    <span class="text-caption ">@((memory / 1024.00 / 1024 / 1024).ToString("F2") + " GB")</span>
                                </div>
                            </div>
                        </MProgressCircular>

                        <div class="mt-1  d-flex align-center justify-space-between">
                            <span class="text-caption">@AppService.I18n.T("内存使用率")</span>
                        </div>
                    </div>
                </MCol>
                <MCol Md=4 Cols="12" Class="pl-2 pr-2 d-flex justify-space-around">
                    @{
                        var totalFreeSpace = _hardwareInfoWorker.APPInfo.DriveInfo.TotalFreeSpace;
                        var totalSize = _hardwareInfoWorker.APPInfo.DriveInfo.TotalSize;
                    }
                    <div class="pl-2 pr-2 d-flex flex-column  align-center">
                        <MProgressCircular Value=@(totalSize>totalFreeSpace?100 - (totalFreeSpace * 100.00 / totalSize):100) Size="160" Width="12" Class="ma-4" Color=@(totalFreeSpace * 100.00 / totalSize<20?"red":"green")>
                            <div class="pl-2 pr-2 d-flex flex-column  align-center">
                                @((100 - (totalFreeSpace * 100.00 / totalSize)).ToString("F2") + " %")
                                <div>
                                    @(_hardwareInfoWorker.APPInfo.DriveInfo.VolumeLabel)
                                </div>
                                <div class="pt-1  d-flex align-center justify-space-between">
                                    <span class="text-caption grey--text mx-2">空闲</span>
                                    <span class="text-caption ">@((totalFreeSpace / 1024.00 / 1024 / 1024).ToString("F2") + " GB")</span>
                                </div>
                                <div class="pt-1  d-flex align-center justify-space-between">
                                    <span class="text-caption grey--text mx-2">总</span>
                                    <span class="text-caption ">@((totalSize / 1024.00 / 1024 / 1024).ToString("F2") + " GB")</span>
                                </div>
                            </div>
                        </MProgressCircular>

                        <div class="mt-1  d-flex align-center justify-space-between">
                            <span class="text-caption">@AppService.I18n.T("磁盘使用率")</span>
                        </div>
                    </div>


                </MCol>
            </MRow>



        </MCard>
    </MCol>




</MRow>

<MCard MinHeight=500 Rounded=true Elevation=1 Class="ma-2">
    <MCardSubtitle Class="text-subtitle-1">
        @AppService.I18n.T("历史信息")
    </MCardSubtitle>
    <MDivider></MDivider>
    <MRow Class="pa-4" NoGutters Align="AlignTypes.Center" Justify="JustifyTypes.Start">

         <MECharts Option="eChartsOption" Width="@("100%")" MinHeight="400"></MECharts>

     </MRow>
 </MCard>







